//https://leetcode.cn/problems/increasing-subsequences/
package codeRandomThoughts.Test491递增子序列;

import java.util.ArrayList;
import java.util.List;

public class Solution2 {
    List<Integer> path = new ArrayList<>();
    List<List<Integer>> result = new ArrayList<>();

    public List<List<Integer>> findSubsequences(int[] nums) {
        backtracking(nums, 0);
        return result;
    }

    public void backtracking(int[] nums, int startIndex) {
        if (path.size() <= nums.length) {
            if (path.size() >= 2) {
                result.add(new ArrayList<>(path));
            }
        } else {
            return;
        }


        boolean[] used = new boolean[201];
        for (int i = startIndex; i < nums.length; i++) {
            //当前项比上一项大才加入path
            if (!used[nums[i] + 100]) {
                used[nums[i] + 100] = true;
                if (path.isEmpty() || path.get(path.size() - 1) <= nums[i]) {
                    path.add(nums[i]);
                    backtracking(nums, i + 1);
                    if (path.size() > 0) path.remove(path.size() - 1);
                }
            }
        }
    }
}
